const xpathListen = `
    function stringToLowerCase(str) {
        if(typeof str === 'string') {
            return str.toLowerCase()
        }else{
          return ''
        }
    }
    function getXpath(element) {
        let xpath = ""
        for(let me=element,k=0; me && me.nodeType === 1 ;element = element.parentNode, me = element, k+=1) {
            let i = 0
            while((me = me.previousElementSibling)) {
                if(me.tagName == element.tagName) {
                    i += 1
                }
            }
            const elementTag = stringToLowerCase(element.tagName)
            let id = i + 1
            id>1 || k===0 ? (id = '[' + id + ']'):(id = '')
            xpath = '/' + elementTag + id +xpath
        }
        return xpath
    }
    var curr
    document.addEventListener('click',e=>{
        curr = getXpath(e.target)
        //console.log(curr)
        localStorage.setItem('curr',curr)
    })
`
module.exports = {
    xpathListen
}
